package cn.topevery.garden.dal.dao.impl;

import cn.topevery.garden.dal.dao.StoreInoutDetailDao;
import cn.topevery.garden.entity.po.StoreInoutDetail;
import cn.topevery.garden.entity.query.StoreInoutDetailQuery;
import cn.topevery.garden.entity.vo.StoreInoutDetailVO;
import cn.topevery.garden.framework.base.BaseDaoImpl;
import hw.topevery.framework.db.entity.DataPager;
import hw.topevery.framework.db.entity.SqlQueryMate;
import hw.topevery.framework.db.enums.ScriptConditionEnum;
import hw.topevery.framework.entity.DbCsp;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 
 *
 * @author code-generate
 * @date 2021-08-30
 */
@Repository
public class StoreInoutDetailDaoImpl extends BaseDaoImpl<StoreInoutDetail> implements StoreInoutDetailDao {
    @Override
    public <P extends DbCsp> List<StoreInoutDetail> getSearch(P para) {
        return null;
    }

    

    @Override
    public DataPager<StoreInoutDetail> listPage(StoreInoutDetailQuery query) {
        String table = "t_store_inout_detail tsid";

        String columns = "tsid.*";

        Integer pageSize = query.pageSize;
        Integer pageIndex = query.pageIndex-1;

        SqlQueryMate sqlQueryMate = new SqlQueryMate(table).setColumns(columns).setOrderBy("tsid.c_db_create_date desc");
        sqlQueryMate
                .where(true, "tsid.c_db_status", ScriptConditionEnum.Eq, 0)
                .where(query.getPId() != null, "tsid.c_inout_id", ScriptConditionEnum.Eq, query.getPId())
                .where(query.getType() != null, "tsid.c_type", ScriptConditionEnum.Eq, query.getType())
                .where(StringUtils.isNotEmpty(query.getName()) , "tsid.c_store_name", ScriptConditionEnum.Eq, query.getName())
        ;

        return getDataPager(sqlQueryMate, pageSize, pageIndex, StoreInoutDetail.class);
    }

    /**
     * 描述 获取盘点清单
     *
     * @param name the name
     * @param type the type
     * @return the list by name
     * @author wenzhao.lin
     * @created 2021 -09-13 15:53:43
     */
    @Override
    public List<StoreInoutDetailVO> getListByName(String name, Integer type) {
        String table = " t_store_inout_detail d  " +
                "left join t_store_inout s on s.c_id = d.c_inout_id ";

        String columns = "d.c_store_name,d.c_store_unit,d.c_store_type_name,d.c_num,s.c_bill_code,s.c_bill_date,s.c_record_user_name,s.c_db_last_update_date ";

        SqlQueryMate sqlQueryMate = new SqlQueryMate(table).setColumns(columns).setOrderBy("s.c_bill_date desc");
        sqlQueryMate
                .where(true, "d.c_db_status", ScriptConditionEnum.Eq, 0)
                .where(type != null, "d.c_type", ScriptConditionEnum.Eq, type)
                .where(StringUtils.isNotEmpty(name) , "d.c_store_name", ScriptConditionEnum.Eq, name)
        ;

        return selectList(sqlQueryMate, StoreInoutDetailVO.class);
    }
}
